//
//  ImageAndLabelCollectionReusableView.m
//  Gift
//
//  Created by dllo on 16/8/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ImageAndLabelCollectionReusableView.h"
#import "ImageAndLabelCollectionViewCell.h"
#define kCollecitonViewCellReuse @"collectionReuse"
#define kCollectionViewReuse @"imageAndLabelReuse"
@interface ImageAndLabelCollectionReusableView ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation ImageAndLabelCollectionReusableView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, CGRectGetWidth(frame) * 0.2, 50)];
        _label.text = @"栏目";
        [self addSubview:_label];
        
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(CGRectGetWidth(frame) * 0.7, 0, CGRectGetWidth(frame) * 0.3, 50);
        [_button setTitle:@"查看全部" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self addSubview:_button];
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        CGFloat itemWidth = CGRectGetWidth(frame) * 0.8;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        flowLayout.itemSize = CGSizeMake(itemWidth, (CGRectGetHeight(frame) - 80) / 3);
        flowLayout.minimumLineSpacing = 20;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 10, 0);
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(5, 50, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds) - 50) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [self addSubview:_collectionView];
        [_collectionView registerClass:[ImageAndLabelCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewReuse];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 9;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    ImageAndLabelCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewReuse forIndexPath:indexPath];

    return cell;
}
@end
